package com.asshole.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
//    MD5加密
    public static String md5(String text){
        MessageDigest digest=null;
        try {
            digest=MessageDigest.getInstance("md5");
            byte[]result=digest.digest(text.getBytes());
            StringBuilder  stringBuilder=new StringBuilder();
            for (byte b:result){
                int number=b&0xff;
                String hex=Integer.toHexString(number);
                if (hex.length()==1){
                    stringBuilder.append("0"+hex);
                }else {
                    stringBuilder.append(hex);
                }
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
